"""
@author: xyl
@file: 反转链表.py
@time: 2022/12/7 11:02
"""

class ListNode():
    def __init__(self,val,next=None):
        if isinstance(val,int):
            self.val = val
            self.next = next
        elif isinstance(val,list):
            self.val = val[0]
            self.next = None
            head = self
            for i in range(1,len(val)):
                node = ListNode(val[i])
                head.next = node
                head = head.next

class Solution():
    def reverseList(self, head):
        prev, curr = None, head
        while curr is not None:
            next = curr.next
            curr.next = prev
            prev = curr       #继续处理后面的链表
            curr = next
        return prev

l = [11,20,23,34,25]
list_node = ListNode(l)
obj = Solution()
reve_list_node = obj.reverseList(list_node)
while reve_list_node:
    print(reve_list_node.val)
    reve_list_node = reve_list_node.next
